package com.hr.controller.admin;

import com.hr.domain.query.LoginLogPageParams;
import com.hr.domain.query.LoginLogPageResult;
import com.hr.service.UserLoginLogService;
import com.hr.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController()
@RequestMapping("/admin")
@Tag(name = "后台登录日志管理")
@AllArgsConstructor
public class UserLoginLogController {

    private final UserLoginLogService userLoginLogService;

    /**
     * 分页获取登录日志列表
     * @return loginLogList
     */
    @GetMapping("/loginLog/page")
    @Operation(summary = "分页获取登录日志列表")
    public Result getLoginLogList(LoginLogPageParams queryParams) {
        log.info("分页获取登录日志列表");
        LoginLogPageResult loginLogPageResult = userLoginLogService.PageLoginLogList(queryParams);
        return Result.success(loginLogPageResult);
    }
    /**
     * 删除登录日志
     * @return msg
     */
    @DeleteMapping("/loginLog/delete/{id}")
    @Operation(summary = "删除单条登录日志")
    public Result deleteLoginLog(@PathVariable("id") Long LogId) {
        log.info("删除登录日志");
        String msg = userLoginLogService.deleteLoginLog(LogId);
        return Result.success("删除成功");
    }
    /**
     * 批量删除登录日志
     * @return msg
     */
    @PostMapping("/loginLog/deleteBatch")
    @Operation(summary = "批量删除登录日志")
    public Result deleteLoginLogBatch(@RequestBody List<Long> logIds) {
        log.info("批量删除登录日志");
        String msg = userLoginLogService.deleteLoginLogBatch(logIds);
        return Result.success("删除成功");
    }

}
